import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
//import componentsRouter from './modules/components'
//import tableRouter from './modules/table'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '统计预览', icon: 'icontongjiyulan', affix: true, role: [1] }
      }
    ]
  },
  {
    path: '/manage',
    component: Layout,
    redirect: '/manage/index',
    meta: {
      title: "设备管理", icon: 'iconPOSji', role: [2]
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/management/index'),
        name: 'Manage',
        meta: { title: '设备管理', icon: 'guide', noCache: true },
        hidden: true
      },
      {
        path: '/manage/edit',
        component: () => import('@/views/management/components/editManage'),
        name: 'editManage',
        meta: { title: '设备管理新增', noCache: true },
        hidden: true
      },
      {
        path: '/manage/detail',
        component: () => import('@/views/management/components/detailManage'),
        name: 'detailManage',
        meta: { title: '设备管理详情', noCache: true },
        hidden: true
      }
    ]
  },
  {
    path: '/money',
    component: Layout,
    redirect: '/money/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/money/index'),
        name: 'money',
        meta: { title: '收款管理', icon: 'iconshoukuan', noCache: true, role: [3] }
      },
      {
        path: '/money/edit',
        component: () => import('@/views/money/components/editManage'),
        name: 'moneyEdit',
        meta: { title: '收款管理新增', noCache: true },
        hidden: true
      },
      {
        path: '/money/detail',
        component: () => import('@/views/money/components/detailManage'),
        name: 'detailMoney',
        meta: { title: '收款账号管理详情', noCache: true },
        hidden: true
      }
    ]
  },
  {
    path: '/project',
    component: Layout,
    redirect: '/project/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/project/index'),
        name: 'project',
        meta: { title: '项目管理', icon: 'iconAPPtubiaozhuanqu-', noCache: true, role: [4] }
      },
      {
        path: '/project/edit',
        component: () => import('@/views/project/components/editProject'),
        name: 'editProject',
        meta: { title: '项目管理', noCache: true },
        hidden: true
      },
      {
        path: '/project/editDetail',
        component: () => import('@/views/project/components/edit'),
        name: 'editProject',
        meta: { title: '项目管理编辑', noCache: true },
        hidden: true
      },
      {
        path: '/project/editM',
        component: () => import('@/views/project/components/editM'),
        name: 'edit',
        meta: { title: '项目管理编辑', noCache: true },
        hidden: true
      },
      {
        path: '/project/mDetail',
        component: () => import('@/views/project/components/mDetail'),
        name: 'edit',
        meta: { title: '设备详情', noCache: true },
        hidden: true
      },
      {
        path: '/project/detail',
        component: () => import('@/views/project/components/detailProject'),
        name: 'detailProject',
        meta: { title: '项目管理详情', noCache: true },
        hidden: true
      },
      {
        path: '/project/collection',
        component: () => import('@/views/project/components/collection'),
        name: 'collection',
        meta: { title: '项目管理配置', noCache: true },
        hidden: true
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/order/index'),
        name: 'order',
        meta: { title: '订单管理', icon: 'iconicon--copy', noCache: true, role: [5] }
      },
      {
        path: '/order/detail',
        component: () => import('@/views/order/components/detailProject'),
        name: 'detailOrder',
        meta: { title: '订单管理详情', noCache: true },
        hidden: true
      },
      {
        path: '/order/contact',
        component: () => import('@/views/order/components/contact'),
        name: 'contact',
        meta: { title: '关联销售单', noCache: true },
        hidden: true
      },
    ]
  },
  {
    path: '/record',
    component: Layout,
    redirect: '/record/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/record/index'),
        name: 'Guide',
        meta: { title: '单据管理', icon: 'iconicon--copy', noCache: true, role: [6] }
      }, {
        path: '/record/detail',
        component: () => import('@/views/record/components/detailProject'),
        name: 'detailOrder',
        meta: { title: '单据管理详情', noCache: true },
        hidden: true
      },
    ]
  },
  {
    path: '/ad',
    component: Layout,
    redirect: '/ad/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/ad/index'),
        name: 'Ad',
        meta: { title: '广告管理', icon: 'iconguanggaogongguan', noCache: true, role: [7] }
      }, {
        path: '/ad/detail',
        component: () => import('@/views/ad/components/detailProject'),
        name: 'detailAd',
        meta: { title: '广告管理详情', noCache: true },
        hidden: true
      },
      {
        path: '/ad/edit',
        component: () => import('@/views/ad/components/editProject'),
        name: 'editAd',
        meta: { title: '广告管理详情', noCache: true },
        hidden: true
      }
    ]
  },
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    meta: { title: '系统管理', icon: 'iconsystem', noCache: true },
    // hidden: true,
    alwaysShow: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: 'Profile',
        meta: { title: '操作日志', noCache: true },
        hidden: false
      },
      // {
      //   path: '/profile/money',
      //   component: () => import('@/views/profile/money'),
      //   name: 'Profile',
      //   meta: { title: '预约金设置', noCache: true, role: [40] },

      // }
    ]
  },

]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [

  // {
  //   path: 'home',
  //   component: () => import('@/views/dashboard/index'),
  //   name: 'Dashboard',
  //   meta: { title: '统计预览', icon: 'nested', affix: true, role: [1] }
  // }




  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
